package com.springcloud.sc.ucpv5.client.commondata.data;

import com.springcloud.sc.ucpv5.client.commondata.datachange.DataExChange;
import com.google.protobuf.Message;

/**
 * Generated from IDL struct "CmdMsg".
 *
 * @author JacORB IDL compiler V 2.3-beta-2, 14-Oct-2006
 * @version generated at 2014-10-29 11:48:54
 */

public final class CmdMsg extends DataExChange {
    public CmdMsg() {
    }

    public int lNEID;
    public String strTableName = "";
    public int lCmdCode;
    public int lLogCmdCode;
    public com.springcloud.sc.ucpv5.client.commondata.data.CmdParam[][] recs;
    public com.springcloud.sc.ucpv5.client.commondata.data.ConditionParam[][] conditonRecs;
    public com.springcloud.sc.ucpv5.client.commondata.data.PageParam PageValue;
    public int lErrorCode;
    public String strErrorMsg = "";

    public CmdMsg(int lNEID, String strTableName, int lCmdCode, int lLogCmdCode, com.springcloud.sc.ucpv5.client.commondata.data.CmdParam[][] recs,
	    com.springcloud.sc.ucpv5.client.commondata.data.ConditionParam[][] conditonRecs, com.springcloud.sc.ucpv5.client.commondata.data.PageParam PageValue, int lErrorCode,
	    String strErrorMsg) {
	this.lNEID = lNEID;
	this.strTableName = strTableName;
	this.lCmdCode = lCmdCode;
	this.lLogCmdCode = lLogCmdCode;
	this.recs = recs;
	this.conditonRecs = conditonRecs;
	this.PageValue = PageValue;
	this.lErrorCode = lErrorCode;
	this.strErrorMsg = strErrorMsg;
    }

    public Message dataChangeCommonToProBufData() {
	try {
	    com.proto.uuos_sdk_pb.CmdMsg.Builder builder_dst = com.proto.uuos_sdk_pb.CmdMsg.newBuilder();
	    builder_dst.setLNEID(lNEID);
	    builder_dst.setStrTableName(strTableName);
	    builder_dst.setLCmdCode(lCmdCode);
	    builder_dst.setLLogCmdCode(lLogCmdCode);

	    for (int i = 0; i < recs.length; i++) {
		com.proto.uuos_sdk_pb.CmdParamSeq.Builder cmdParamSeqBuilder = com.proto.uuos_sdk_pb.CmdParamSeq.newBuilder();
		for (int j = 0; j < recs[i].length; j++) {
		    CmdParam cmdParam = recs[i][j];

		    com.proto.uuos_sdk_pb.CmdParam.Builder cmdParamPfBuilder = com.proto.uuos_sdk_pb.CmdParam.newBuilder();
		    cmdParamPfBuilder.setStrName(cmdParam.strName);
		    cmdParamPfBuilder.setStrValue(cmdParam.strValue);

		    cmdParamSeqBuilder.addCps(cmdParamPfBuilder.build());
		}
		builder_dst.addRecs(cmdParamSeqBuilder.build());
	    }

	    for (int i = 0; i < conditonRecs.length; i++) {
		com.proto.uuos_sdk_pb.ConditionParamSeq.Builder cmdParamSeqBuilder = com.proto.uuos_sdk_pb.ConditionParamSeq.newBuilder();
		for (int j = 0; j < conditonRecs[i].length; j++) {
		    ConditionParam cmdParam = conditonRecs[i][j];

		    com.proto.uuos_sdk_pb.ConditionParam.Builder cmdParamPfBuilder = com.proto.uuos_sdk_pb.ConditionParam.newBuilder();
		    cmdParamPfBuilder.setStrName(cmdParam.strName);
		    cmdParamPfBuilder.setStrValue(cmdParam.strValue);
		    cmdParamPfBuilder.setStrSign(cmdParam.strSign);

		    cmdParamSeqBuilder.addCops(cmdParamPfBuilder.build());
		}
		builder_dst.addConditonRecs(cmdParamSeqBuilder.build());
	    }

	    com.proto.uuos_sdk_pb.PageParam pageParam = (com.proto.uuos_sdk_pb.PageParam) PageValue.dataChangeCommonToProBufData();

	    builder_dst.setPageValue(pageParam);

	    builder_dst.setLErrorCode(lErrorCode);
	    builder_dst.setStrErrorMsg(strErrorMsg);

	    Message pbMessage = builder_dst.build();
	    return pbMessage;
	} catch (Exception e) {
	    e.printStackTrace();
	}

	return null;
    }

    /**
     * 从probuf对象获取当前对象
     * 
     * @param builder_src
     * @return
     */
    public void dataChangeProBufDataToCommon(Message builder_src) {
	try {
	    com.proto.uuos_sdk_pb.CmdMsg cmdMsgPf = (com.proto.uuos_sdk_pb.CmdMsg) builder_src;
	    lNEID = cmdMsgPf.getLNEID();
	    strTableName = cmdMsgPf.getStrTableName();
	    lCmdCode = cmdMsgPf.getLCmdCode();
	    lLogCmdCode = cmdMsgPf.getLLogCmdCode();

	    if (cmdMsgPf.getRecsCount() > 0) {
		recs = new CmdParam[cmdMsgPf.getRecsCount()][];
		for (int i = 0; i < cmdMsgPf.getRecsCount(); i++) {
		    com.proto.uuos_sdk_pb.CmdParamSeq seq = cmdMsgPf.getRecs(i);
		    if (seq.getCpsCount() > 0) {
			recs[i] = new CmdParam[seq.getCpsCount()];
			for (int j = 0; j < seq.getCpsCount(); j++) {
			    com.proto.uuos_sdk_pb.CmdParam cmdParamPf = seq.getCps(j);
			    recs[i][j] = new CmdParam();
			    recs[i][j].strName = cmdParamPf.getStrName();
			    recs[i][j].strValue = cmdParamPf.getStrValue();
			}

		    }
		}
	    }

	    if (cmdMsgPf.getConditonRecsCount() > 0) {
		conditonRecs = new ConditionParam[cmdMsgPf.getConditonRecsCount()][];
		for (int i = 0; i < cmdMsgPf.getConditonRecsCount(); i++) {
		    com.proto.uuos_sdk_pb.ConditionParamSeq seq = cmdMsgPf.getConditonRecs(i);
		    if (seq.getCopsCount() > 0) {
			conditonRecs[i] = new ConditionParam[seq.getCopsCount()];
			for (int j = 0; j < seq.getCopsCount(); j++) {
			    com.proto.uuos_sdk_pb.ConditionParam cmdParamPf = seq.getCops(j);
			    conditonRecs[i][j] = new ConditionParam();
			    conditonRecs[i][j].strName = cmdParamPf.getStrName();
			    conditonRecs[i][j].strValue = cmdParamPf.getStrValue();
			    conditonRecs[i][j].strSign = cmdParamPf.getStrName();
			}

		    }
		}
	    }

	    PageParam pageParam = new PageParam();
	    pageParam.dataChangeProBufDataToCommon(cmdMsgPf.getPageValue());
	    PageValue = pageParam;

	    lErrorCode = cmdMsgPf.getLErrorCode();
	    strErrorMsg = cmdMsgPf.getStrErrorMsg();
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }

    public org.omg.CORBA.portable.IDLEntity dataChangeCommonToCorbarData() {
	try {
	    com.springcloud.sc.ucpv5.client.commondata.idl.sj3.CmdMsg builder_dst = new com.springcloud.sc.ucpv5.client.commondata.idl.sj3.CmdMsg();
	    builder_dst.lNEID = lNEID;
	    builder_dst.strTableName = strTableName;
	    builder_dst.lCmdCode = lCmdCode;
	    builder_dst.lLogCmdCode = lLogCmdCode;

	    com.springcloud.sc.ucpv5.client.commondata.idl.sj3.CmdParam[][] recs_ = new com.springcloud.sc.ucpv5.client.commondata.idl.sj3.CmdParam[recs.length][];
	    for (int i = 0; i < recs.length; i++) {
		recs_[i] = new com.springcloud.sc.ucpv5.client.commondata.idl.sj3.CmdParam[recs[i].length];
		for (int j = 0; j < recs[i].length; j++) {
		    recs_[i][j] = new com.springcloud.sc.ucpv5.client.commondata.idl.sj3.CmdParam();
		    recs_[i][j].strName = recs[i][j].strName;
		    recs_[i][j].strValue = recs[i][j].strValue;
		}
	    }
	    builder_dst.recs = recs_;
	    
	    com.springcloud.sc.ucpv5.client.commondata.idl.sj3.ConditionParam[][] conditonRecs_ = new com.springcloud.sc.ucpv5.client.commondata.idl.sj3.ConditionParam[conditonRecs.length][];
	    for (int i = 0; i < conditonRecs.length; i++) {
		conditonRecs_[i] = new com.springcloud.sc.ucpv5.client.commondata.idl.sj3.ConditionParam[conditonRecs[i].length];
		for (int j = 0; j < conditonRecs[i].length; j++) {
		    conditonRecs_[i][j] = new com.springcloud.sc.ucpv5.client.commondata.idl.sj3.ConditionParam();
		    conditonRecs_[i][j].strName = conditonRecs[i][j].strName;
		    conditonRecs_[i][j].strValue = conditonRecs[i][j].strValue;
		}
	    }
	    builder_dst.conditonRecs = conditonRecs_;
	    
	    builder_dst.PageValue = (com.springcloud.sc.ucpv5.client.commondata.idl.sj3.PageParam) PageValue.dataChangeCommonToCorbarData();

	    builder_dst.lErrorCode = lErrorCode;
	    builder_dst.strErrorMsg = strErrorMsg;

	    return builder_dst;
	} catch (Exception e) {
	    e.printStackTrace();
	}

	return null;
    }

    public void dataChangeCorbarDataToCommon(org.omg.CORBA.portable.IDLEntity builder_src) {
	try {
	    com.springcloud.sc.ucpv5.client.commondata.idl.sj3.CmdMsg cmdMsgPf = (com.springcloud.sc.ucpv5.client.commondata.idl.sj3.CmdMsg) builder_src;
	    lNEID = cmdMsgPf.lNEID;
	    strTableName = cmdMsgPf.strTableName;
	    lCmdCode = cmdMsgPf.lCmdCode;
	    lLogCmdCode = cmdMsgPf.lLogCmdCode;
	    
	    int size = cmdMsgPf.recs.length;
	    if(recs != null && recs.length > 0){
		 size = size + recs.length; 
	    }
	    com.springcloud.sc.ucpv5.client.commondata.data.CmdParam[][] recs_new = new com.springcloud.sc.ucpv5.client.commondata.data.CmdParam[size][];
	    int index = 0;
	    if(recs != null  && recs.length > 0){
		 for (int i = 0; i < recs.length; i++) {
		     recs_new[index] = recs[i];
		     index++;
		}
	    }
	    
	    for (int i = 0; i < cmdMsgPf.recs.length; i++) {
		recs_new[index] = new com.springcloud.sc.ucpv5.client.commondata.data.CmdParam[cmdMsgPf.recs[i].length];
		for (int j = 0; j < cmdMsgPf.recs[i].length; j++) {
		    recs_new[index][j] = new com.springcloud.sc.ucpv5.client.commondata.data.CmdParam();
		    recs_new[index][j].strName = cmdMsgPf.recs[i][j].strName;
		    recs_new[index][j].strValue = cmdMsgPf.recs[i][j].strValue;
		}
		index++;
	    }
	    
	    recs = recs_new;
	    
	    conditonRecs = new com.springcloud.sc.ucpv5.client.commondata.data.ConditionParam[cmdMsgPf.conditonRecs.length][];
	    for (int i = 0; i < cmdMsgPf.conditonRecs.length; i++) {
		conditonRecs[i] = new com.springcloud.sc.ucpv5.client.commondata.data.ConditionParam[cmdMsgPf.conditonRecs[i].length];
		for (int j = 0; j < cmdMsgPf.conditonRecs[i].length; j++) {
		    conditonRecs[i][j] = new com.springcloud.sc.ucpv5.client.commondata.data.ConditionParam();
		    conditonRecs[i][j].strName = cmdMsgPf.conditonRecs[i][j].strName;
		    conditonRecs[i][j].strValue = cmdMsgPf.conditonRecs[i][j].strValue;
		}
	    }
	    
	    PageParam pageParam = new PageParam();
	    pageParam.dataChangeCorbarDataToCommon(cmdMsgPf.PageValue);
	    PageValue = pageParam;

	    lErrorCode = cmdMsgPf.lErrorCode;
	    strErrorMsg = cmdMsgPf.strErrorMsg;
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}
